dump-core: always use elfclass64 format to support x86_32pae.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 7 Mar 2007 10:53:34 +0000 (10:53 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 7 Mar 2007 10:53:34 +0000 (10:53 +0000)
Without this patch xen dump-core format can't handle over 4GB case.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
docs/misc/dump-core-format.txt
tools/libxc/xc_core.c
tools/libxc/xc_core.h
tools/libxc/xc_core_ia64.c
tools/libxc/xc_core_ia64.h
tools/libxc/xc_core_x86.h
tools/libxc/xc_ptrace_core.c

index ce759f39a0bcd7cf19cd235148dea4bd010268cc..99384ca94a0ddc4557c8669a6d281f5807c19050 100644 (file)
@@ -26,11 +26,12 @@ For xen related structure, please see the xen header files.
 Elf header
 ----------
 The elf header members are set as follows
+        e_ident[EI_CLASS] = ELFCLASS64 = 2
         e_ident[EI_OSABI] = ELFOSABI_SYSV = 0
         e_type = ET_CORE = 4
-e_ident[EI_CLASS], e_ident[EI_DATA] and e_flags are set according
-to an architecture which a file is created. Other members are set as usual.
-
+ELFCLASS64 is always used independent of architecture.
+e_ident[EI_DATA] and e_flags are set according to the dumping system's
+architecture. Other members are set as usual.
 
 Sections
 --------
@@ -221,5 +222,10 @@ format_version descriptor
 
 Format version history
 ----------------------
-The currently only (major, minor) = (0, 1) is used.
+Currently only (major, minor) = (0, 1) is used.
 [When the format is changed, it would be described here.]
+
+(0, 1) update
+- EI_CLASS member of elf header was changed to ELFCLASS64 independent of
+  architecture. This is mainly for x86_32pae.
+  The format version isn't bumped because analysis tools can distinguish it.
index 7f6f0ee67a2da29cffdb4ea7e7c04b9ce13747cd..3dcf51e131f49326ba289ff0fa7b60e647c838bb 100644 (file)
@@ -153,7 +153,7 @@ struct xc_core_section_headers {
     uint16_t    num;
     uint16_t    num_max;
 
-    Elf_Shdr   *shdrs;
+    Elf64_Shdr  *shdrs;
 };
 #define SHDR_INIT       16
 #define SHDR_INC        4
@@ -184,14 +184,14 @@ xc_core_shdr_free(struct xc_core_section_headers *sheaders)
     free(sheaders);
 }
 
-Elf_Shdr*
+Elf64_Shdr*
 xc_core_shdr_get(struct xc_core_section_headers *sheaders)
 {
-    Elf_Shdr *shdr;
+    Elf64_Shdr *shdr;
 
     if ( sheaders->num == sheaders->num_max )
     {
-        Elf_Shdr *shdrs;
+        Elf64_Shdr *shdrs;
         if ( sheaders->num_max + SHDR_INC < sheaders->num_max )
         {
             errno = E2BIG;
@@ -212,7 +212,7 @@ xc_core_shdr_get(struct xc_core_section_headers *sheaders)
 }
 
 int
-xc_core_shdr_set(Elf_Shdr *shdr,
+xc_core_shdr_set(Elf64_Shdr *shdr,
                  struct xc_core_strtab *strtab,
                  const char *name, uint32_t type,
                  uint64_t offset, uint64_t size,
@@ -317,15 +317,15 @@ xc_domain_dumpcore_via_callback(int xc_handle,
 
     uint64_t *pfn_array = NULL;
 
-    Elf_Ehdr ehdr;
-    unsigned long filesz;
-    unsigned long offset;
-    unsigned long fixup;
+    Elf64_Ehdr ehdr;
+    uint64_t filesz;
+    uint64_t offset;
+    uint64_t fixup;
 
     struct xc_core_strtab *strtab = NULL;
     uint16_t strtab_idx;
     struct xc_core_section_headers *sheaders = NULL;
-    Elf_Shdr *shdr;
+    Elf64_Shdr *shdr;
 
     /* elf notes */
     struct elfnote elfnote;
@@ -460,7 +460,7 @@ xc_domain_dumpcore_via_callback(int xc_handle,
     ehdr.e_ident[EI_MAG1] = ELFMAG1;
     ehdr.e_ident[EI_MAG2] = ELFMAG2;
     ehdr.e_ident[EI_MAG3] = ELFMAG3;
-    ehdr.e_ident[EI_CLASS] = ELFCLASS;
+    ehdr.e_ident[EI_CLASS] = ELFCLASS64;
     ehdr.e_ident[EI_DATA] = ELF_ARCH_DATA;
     ehdr.e_ident[EI_VERSION] = EV_CURRENT;
     ehdr.e_ident[EI_OSABI] = ELFOSABI_SYSV;
@@ -474,9 +474,9 @@ xc_domain_dumpcore_via_callback(int xc_handle,
     ehdr.e_shoff = sizeof(ehdr);
     ehdr.e_flags = ELF_CORE_EFLAGS;
     ehdr.e_ehsize = sizeof(ehdr);
-    ehdr.e_phentsize = sizeof(Elf_Phdr);
+    ehdr.e_phentsize = sizeof(Elf64_Phdr);
     ehdr.e_phnum = 0;
-    ehdr.e_shentsize = sizeof(Elf_Shdr);
+    ehdr.e_shentsize = sizeof(Elf64_Shdr);
     /* ehdr.e_shnum and ehdr.e_shstrndx aren't known here yet. fill it later*/
 
     /* create section header */
index cf5b15d12b79f67758e34ff6bea7d17ab502c617..5b1c9b5a330f645e38b8fc1ec1e1354389834c8d 100644 (file)
@@ -116,10 +116,10 @@ struct xen_dumpcore_p2m {
 struct xc_core_strtab;
 struct xc_core_section_headers;
 
-Elf_Shdr*
+Elf64_Shdr*
 xc_core_shdr_get(struct xc_core_section_headers *sheaders);
 int
-xc_core_shdr_set(Elf_Shdr *shdr,
+xc_core_shdr_set(Elf64_Shdr *shdr,
                  struct xc_core_strtab *strtab,
                  const char *name, uint32_t type,
                  uint64_t offset, uint64_t size,
index 9ae7dad8c0117cde092dc0be21199df79dc74acc..455d532ee2c8105c4e92258353e0c124eff14e8c 100644 (file)
@@ -266,10 +266,10 @@ int
 xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, 
                               struct xc_core_section_headers *sheaders,
                               struct xc_core_strtab *strtab,
-                              unsigned long *filesz, unsigned long offset)
+                              uint64_t *filesz, uint64_t offset)
 {
     int sts = -1;
-    Elf_Shdr *shdr;
+    Elf64_Shdr *shdr;
 
     /* mmapped priv regs */
     shdr = xc_core_shdr_get(sheaders);
index 1690e0168988e629dcafa4667ecf83d370ae8c4c..6357dfa20eb9846f56a8aa547f5bf09b61ddedc4 100644 (file)
@@ -42,7 +42,7 @@ int
 xc_core_arch_context_get_shdr(struct xc_core_arch_context* arch_ctxt, 
                               struct xc_core_section_headers *sheaders,
                               struct xc_core_strtab *strtab,
-                              unsigned long *filesz, unsigned long offset);
+                              uint64_t *filesz, uint64_t offset);
 int
 xc_core_arch_context_dump(struct xc_core_arch_context* arch_ctxt,
                           void* args, dumpcore_rtn_t dump_rtn);
index b3c2d5beec6cf80372c9fab9bd2652ec9a377f83..53ca48493d2c16e66ab52fd46d30886d353a0817 100644 (file)
@@ -45,7 +45,7 @@ static inline int
 xc_core_arch_context_get_shdr(struct xc_core_arch_context *arch_ctxt, 
                               struct xc_core_section_headers *sheaders,
                               struct xc_core_strtab *strtab,
-                              unsigned long *filesz, unsigned long offset)
+                              uint64_t *filesz, uint64_t offset)
 {
     *filesz = 0;
     return 0;
index 419b3e55af3d3d32ab9b067cc7613092a2878c0f..82d06bb2d8c901c04b327e58c5f50f99a8e19630 100644 (file)
@@ -192,7 +192,7 @@ pread_exact(int fd, void* buffer, size_t size, off_t offset)
 struct elf_core
 {
     int         domfd;
-    Elf_Ehdr    ehdr;
+    Elf64_Ehdr  ehdr;
 
     char*       shdr;
     
@@ -242,6 +242,8 @@ elf_core_init(struct elf_core* ecore, int domfd)
     /* check elf header */
     if (!IS_ELF(ecore->ehdr) || ecore->ehdr.e_type != ET_CORE)
         goto out;
+    if (ecore->ehdr.e_ident[EI_CLASS] != ELFCLASS64)
+        goto out;
     /* check elf header more: EI_DATA, EI_VERSION, e_machine... */
 
     /* read section headers */
@@ -294,7 +296,7 @@ elf_core_search_note(struct elf_core* ecore, const char* name, uint32_t type,
 }
 
 static int
-elf_core_alloc_read_sec(struct elf_core* ecore, const Elf_Shdr* shdr,
+elf_core_alloc_read_sec(struct elf_core* ecore, const Elf64_Shdr* shdr,
                         char** buf)
 {
     int ret;
@@ -309,19 +311,19 @@ elf_core_alloc_read_sec(struct elf_core* ecore, const Elf_Shdr* shdr,
     return ret;
 }
 
-static Elf_Shdr*
+static Elf64_Shdr*
 elf_core_shdr_by_index(struct elf_core* ecore, uint16_t index)
 {
     if (index >= ecore->ehdr.e_shnum)
         return NULL;
-    return (Elf_Shdr*)(ecore->shdr + ecore->ehdr.e_shentsize * index);
+    return (Elf64_Shdr*)(ecore->shdr + ecore->ehdr.e_shentsize * index);
 }
 
 static int
 elf_core_alloc_read_sec_by_index(struct elf_core* ecore, uint16_t index,
                                  char** buf, uint64_t* size)
 {
-    Elf_Shdr* shdr = elf_core_shdr_by_index(ecore, index);
+    Elf64_Shdr* shdr = elf_core_shdr_by_index(ecore, index);
     if (shdr == NULL)
         return -1;
     if (size != NULL)
@@ -329,14 +331,14 @@ elf_core_alloc_read_sec_by_index(struct elf_core* ecore, uint16_t index,
     return elf_core_alloc_read_sec(ecore, shdr, buf);
 }
 
-static Elf_Shdr*
+static Elf64_Shdr*
 elf_core_shdr_by_name(struct elf_core* ecore, const char* name)
 {
     const char* s;
     for (s = ecore->shdr;
          s < ecore->shdr + ecore->ehdr.e_shentsize * ecore->ehdr.e_shnum;
          s += ecore->ehdr.e_shentsize) {
-        Elf_Shdr* shdr = (Elf_Shdr*)s;
+        Elf64_Shdr* shdr = (Elf64_Shdr*)s;
 
         if (strncmp(ecore->shstrtab + shdr->sh_name, name, strlen(name)) == 0)
             return shdr;
@@ -348,7 +350,7 @@ elf_core_shdr_by_name(struct elf_core* ecore, const char* name)
 static int
 elf_core_read_sec_by_name(struct elf_core* ecore, const char* name, char* buf)
 {
-    Elf_Shdr* shdr = elf_core_shdr_by_name(ecore, name);
+    Elf64_Shdr* shdr = elf_core_shdr_by_name(ecore, name);
     return pread_exact(ecore->domfd, buf, shdr->sh_size, shdr->sh_offset);
     
 }
@@ -357,7 +359,7 @@ static int
 elf_core_alloc_read_sec_by_name(struct elf_core* ecore, const char* name,
                                 char** buf, uint64_t* size)
 {
-    Elf_Shdr* shdr = elf_core_shdr_by_name(ecore, name);
+    Elf64_Shdr* shdr = elf_core_shdr_by_name(ecore, name);
     if (shdr == NULL)
         return -1;
     if (size != NULL)
@@ -508,8 +510,8 @@ xc_waitdomain_core_elf(
     struct xen_dumpcore_elfnote_xen_version *xen_version;
     struct xen_dumpcore_elfnote_format_version *format_version;
 
-    Elf_Shdr* table_shdr;
-    Elf_Shdr* pages_shdr;
+    Elf64_Shdr* table_shdr;
+    Elf64_Shdr* pages_shdr;
 
     if (elf_core_init(&ecore, domfd) < 0)
         goto out;